#include <iostream>
using namespace std;

class Person
{
private:
  /* data */
public:
  int m_a;
  int m_b;
  // 1. 成员函数重载+号
  /* Person operator+(Person &p)
  {
    Person temp;
    temp.m_a = this->m_a + p.m_a;
    temp.m_b = this->m_b + p.m_b;
    return temp;
  } */

public:
  Person();
  Person(int a, int b);
  ~Person();
};

Person::Person(){};

Person::Person(int a, int b) : m_a(a), m_b(b)
{
}

Person::~Person()
{
}

// 2. 全局函数重载+号
Person operator+(Person &p1, Person &p2)
{
  Person temp;
  temp.m_a = p1.m_a + p2.m_a;
  temp.m_b = p1.m_b + p2.m_b;
  return temp;
}

// 函数重载版本
Person operator+(Person &p1, int num)
{
  Person temp;
  temp.m_a = p1.m_a + num;
  temp.m_b = p1.m_b + num;
  return temp;
}

void test01()
{
  Person p1(10, 20);
  Person p2(10, 10);

  // 成员函数重载本质调用
  // Person p3 = p1.operator+(p2);

  // 全局函数本质调用
  // Person p3 = operator+(p1, p2);
  Person p3 = p1 + p2;

  // 运算符重载 也可以发生函数重载
  Person p4 = p1 + 100;

  cout << "p3.m_a = " << p3.m_a << endl;
  cout << "p3.m_b = " << p3.m_b << endl;

  cout << "p4.m_a = " << p4.m_a << endl;
  cout << "p4.m_b = " << p4.m_b << endl;
}

int main(int argc, char const *argv[])
{
  test01();

  return 0;
}